package com.ape.mapsa.produccion.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.ape.mapsa.produccion.model.Color;

@Repository(value = "colorDAO")
@Transactional
public class ColorDAOImpl extends GenericDAOImpl<Color, Long> implements ColorDAO {

	protected SessionFactory sessionFactory;

	@Autowired
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	public ColorDAOImpl() {
	}

	@Override
	public Color findByDescripcion(Color color) {
		try {
			List<Color> findByExample = findByExample(color, "id", "description", "created", "items");
			if (findByExample != null && !findByExample.isEmpty()) {
				return findByExample.get(0);
			} else {
				return null;
			}
		} catch (Exception x) {
			throw x;
		}
	}
}
